<?php //$this->Html->script('jquery-1.4.2.min'); ?>
<div class="widget grid12">
    <div class="whead"><h6>FORMULARIO DE NUEVA ORDEN DE COMPRA</h6><div class="clear"></div></div>
    <?php echo $this->Form->create('Ordene', array('id' => "validate")); ?>
    
    <div class="formRow">
        <div class="grid3"><label>Orden de compra (PO):<span class="req">*</span></label></div>
        <div class="grid9">
            <?php echo $this->Form->text('Ordene.nombre', array('placeholder' => 'Ingrese la Orden Ej: CA-009', "class" => "validate[required, ajax[ajaxvalida]]")); ?>
        </div>
        <div class="clear"></div>
    </div>
    
    <div class="formRow">
        <div class="grid3"><label>Categoria :<span class="req">*</span></label></div>
        <div class="grid9">
            <?php echo $this->Form->select('Ordene.categoria_id', $dcc, array("class" => "validate[required]")); ?>
        </div>
        <div class="clear"></div>
    </div> 

    <div class="formRow">
        <div class="grid3"><label>Volumenes :</label></div>
        <div class="grid9">
            <?php echo $this->Form->text('Ordene.volumenes', array('id' => 's4', 'value' => '1', "class" => "validate[required]")); ?>                        
        </div>
        <div class="clear"></div>
    </div>

    <div class="formRow">
        <div class="grid3"><label>Documentos :</label></div>                        
        <div class="grid9 check">       
            <?php foreach ($documentos as $d): ?>  
                <?php $idDoc = $d['Documento']['id']; ?>                
                <label for="check1" class="mr20"><?php echo $d['Documento']['nombre']; ?></label>
                <?php echo $this->Form->checkbox("DocumentosOrdene.$idDoc.documento_id", array('value' => $idDoc, 'hiddenField' => false)); ?>                                                                                       
                <?php if ($idDoc != 18): ?>
                    <span class="grid3">
                        <?php echo $this->Form->text("DocumentosOrdene.$idDoc.volumen", array('placeholder' => 'Volumen')); ?>    
                    </span>
                <?php endif; ?>
                <?php if (($idDoc == 1) OR ($idDoc == 5) OR ($idDoc == 6) OR ($idDoc == 15)): ?>
                    &nbsp;&nbsp;<?php $verifica = array('1' => 'Original', '0' => 'Copia'); ?>                                                
                    <?php echo $this->Form->select("DocumentosOrdene.$idDoc.original", $verifica); ?>  
                <?php endif; ?>
                <p>&nbsp;</p>
            <?php endforeach; ?>     

        </div>        
        <div class="clear"></div>
    </div>        

    <div class="formRow">
        <div class="grid3"><label>CAF :</label></div>
        <div class="grid3">
            <?php echo $this->Form->text('Ordene.cantidadcaf', array('placeholder' => 'Ingrese Cantidad Ej: 2')); ?>
            <?php //echo $this->Form->text('Ordene.volumencaf', array('placeholder' => 'Ingrese Volumen Ej: 3', "class" => "validate[required]")); ?>
        </div>
        <div class="grid3">
            <?php //echo $this->Form->text('Ordene.cantidadcaf', array('placeholder' => 'Ingrese Cantidad Ej: 3', "class" => "validate[required]")); ?>
            <?php echo $this->Form->text('Ordene.volumencaf', array('placeholder' => 'Ingrese Volumen Ej: 3')); ?>
        </div>        
        <div class="clear"></div>
    </div>

    <div class="formRow">
        <div class="grid3"><label>Observaciones :</label></div>
        <div class="grid9">
            <?php echo $this->Form->hidden('DocumentosOrdene.seleccionados', array('id' => 'seleccionados', 'value' => 0)); ?>
            <?php echo $this->Form->text('Ordene.observaciones', array('placeholder' => 'Ingrese la Orden Ej: CA-009')); ?>
        </div>
        <div class="clear"></div>  
    </div>

    <div class="formRow">
        <div class="grid3"><label>Fecha :</label></div>
        <div class="grid9">
            <?php echo $this->Form->text('Ordene.fecha', array('id' => 'fechaPed', 'placeholder' => 'Ingrese la Fecha del Pedido Formato: (Ano-Mes-Dia)')); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div class="formRow">
        <div class="grid3"><label>Monto :</label></div>
        <div class="grid9">
            <?php echo $this->Form->text('Ordene.monto', array('placeholder' => 'Ingrese Monto')); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div class="formRow">
        <div class="grid3"><label>descripcion:</label></div>
        <div class="grid9">
            <?php echo $this->Form->text('Ordene.descripcion', array('placeholder' => 'Ingrese la descricion')); ?>
        </div>
        <div class="clear"></div>
    </div>     

    <div class="formRow">
        <div class="grid3"><label>Original :</label></div>
        <div class="grid3">            
            <?php echo $this->Form->checkbox("Ordene.original", array('value' => 'S', 'hiddenField' => 'N')); ?>
        </div>

        <div class="grid3"><label>Cant Firmas :</label></div>
        <div class="grid3">            
            <?php echo $this->Form->text('Ordene.firmasoriginal', array('placeholder' => '0')); ?>
            <?php //echo $this->Form->checkbox("tagSel", array('value' => 1, 'hiddenField' => false)); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div class="formRow">
        <div class="grid3"><label>Copia: </label></div>
        <div class="grid3">
            <?php echo $this->Form->checkbox("Ordene.copia", array('value' => "S", 'hiddenField' => 'N')); ?>
        </div>
        <div class="grid3"><label>Cant. Firmas :</label></div>
        <div class="grid3">
            <?php echo $this->Form->text('Ordene.firmascopia', array('placeholder' => '0')); ?>
        </div>        
        <div class="clear"></div>
    </div>


    <!-- sheepIt Form -->
    <div id="sheepItForm">
        <!-- Form template-->
        <div id="sheepItForm_template">
            <div class="formRow">
                <div class="grid2"><label><span id="sheepItForm_label"></span>.- Tag de la Orden :</label></div>
                <div class="grid2 moreFields allUpper">
                    <?php echo $this->Form->text('OrdenesTag.#index#.tag', array('placeholder' => '')); ?>
                </div>
                <div class="grid2"><label>Numero Activo :</label></div>
                <div class="grid2">
                    <?php echo $this->Form->text('OrdenesTag.#index#.nactivo', array('placeholder' => '')); ?>
                </div>
                <div class="grid2"><label>Monto :</label></div>
                <div class="grid2">
                    <?php echo $this->Form->text('OrdenesTag.#index#.monto'); ?>
                    <a id="sheepItForm_remove_current" style="float: left">
                        X<img class="delete" src="/images/cross.png" width="16" height="16" border="0">
                    </a>
                </div>
                <div class="clear"></div>                 
            </div>
        </div>   
        <!-- /Form template-->                  
        <!-- No forms template -->
        <div id="sheepItForm_noforms_template">Ningun Tags</div>
        <!-- /No forms template-->

        <!-- Controls -->
        <div id="sheepItForm_controls">
            <div id="sheepItForm_add"><a class="buttonS bGreen"><span>(+)Mas Tags</span></a></div>
                <p></p>
            <div id="sheepItForm_remove_last"><a class="buttonS bRed"><span>(-)Quitar</span></a></div>
            <div id="sheepItForm_remove_all"><a class="buttonS bRed"><span>(-)Quitar Todos</span></a></div>
            <div id="sheepItForm_add_n">
                <input id="sheepItForm_add_n_input" type="text" size="4" style="border: 1px solid #006;"/>
                    <p></p>
                <div id="sheepItForm_add_n_button"><a class="buttonS bGold"><span>Anadir</span></a></div></div>
        </div>
        <!-- /Controls -->

    </div>
    <!-- /sheepIt Form -->          

    <div class="clear"></div>


</div>

<script>
    $(document).ready(function() {
        
        $( "#fechaPed" ).datepicker({
            defaultDate: +7,
            showOtherMonths:true,
            autoSize: true,
            /*appendText: '(Ano-Mes-Dia)',*/
            dateFormat: 'yy-mm-dd',
            changeMonth: true,
            changeYear: true
        });        
        /* Init the table */
        var oTable = $('.dTable').dataTable( );
        
        /* Add/remove class to a row when clicked on */
        $('.dTable tr').click( function() {
            $(this).toggleClass('row_selected');               
        } );
        
        $('#btEnvia').hover( function() {
            //$(this).toggleClass('row_selected');  
            $.fn.getCheckboxValues = function(){
                var values = [];
                var i = 0;
                this.each(function(){
                    values[i++] = $(this).val();
                });
                return values;
            } 

            var arr = $("input:checked").getCheckboxValues();
            $("#seleccionados").val(arr);
            console.log('es'+arr);
        } );
        
        var sheepItForm = $('#sheepItForm').sheepIt({
            separator: '',
            allowRemoveLast: true,
            allowRemoveCurrent: true,
            allowRemoveAll: true,
            allowAdd: true,
            allowAddN: true,
            maxFormsCount: 150,
            minFormsCount: 1,
            iniFormsCount: 1,
            continuousIndex: true
        });         
        $("#validate").keypress(function(e) {
            if (e.which == 13) {
                //alert('Presiono enter');
                return false;
                
            }
        });                                         
    } );                     
</script>
    <div class="formRow">
        <?php
        $options = array(
            'label' => 'Guardar Datos',
            'class' => 'buttonS bLightBlue',
            'id' => 'btEnvia'
        );
        echo $this->Form->end($options);
        ?> 
        <div class="clear"></div>        
    </div>